//
//  TTPassDiamondInfoViewCell.m
//  TaoTuo
//
//  Created by LG on 2020/8/10.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTPassDiamondInfoViewCell.h"

@interface TTPassDiamondInfoViewCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *resultLabel;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation TTPassDiamondInfoViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setupSubviews];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
}

- (void)setDic:(NSDictionary *)dic
{
    _dic = dic;
    
    self.titleLabel.text = dic[@"leftTitle"];
    self.resultLabel.text = dic[@"rightTitle"];
    
    [self setSubviewsFrame];
}

- (void)setSubviewsFrame
{
//    [super layoutSubviews];
    
    CGFloat leftW = [self.dic[@"leftW"] floatValue];
    CGFloat rightW = [self.dic[@"rightW"] floatValue];
    
    [_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.width.mas_equalTo(leftW);
        make.centerY.equalTo(self.contentView);
    }];
    
    [_resultLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).mas_offset(-10);
        make.width.mas_equalTo(rightW);
        make.centerY.equalTo(self.contentView);
    }];
    
    [_lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).mas_offset(5);
        make.centerY.equalTo(self.titleLabel);
        make.right.equalTo(self.resultLabel.mas_left).mas_offset(-10);
        make.height.mas_equalTo(2);
    }];
    
    
    [self.contentView layoutIfNeeded];
    
    CGFloat lineW = [self.dic[@"lineW"] floatValue];
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointZero];
    [path addLineToPoint:CGPointMake(lineW, 0)];
    
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.frame = _lineView.bounds;
    layer.lineDashPattern = @[@1, @5];
    layer.lineWidth = 1;
    layer.lineCap = kCALineCapRound;
    layer.strokeColor = UIColorHex(#999999).CGColor;
    layer.path = path.CGPath;
    [_lineView.layer addSublayer:layer];
    
    
}

- (void)setupSubviews
{
    _titleLabel = [UILabel labelWithTitle:@"——" color:UIColorHex(#333333) fontSize:11];
    [self.contentView addSubview:_titleLabel];
    
    
    
    _resultLabel = [UILabel labelWithTitle:@"——" color:UIColorHex(#333333) fontSize:11];
    [self.contentView addSubview:_resultLabel];
    
    
    
    _lineView = [[UIView alloc] init];
    _lineView.layer.masksToBounds = YES;
    [self.contentView addSubview:_lineView];
    
    
    
    
    
    
    
}


@end
